package com.example.mymusic.app;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;

import com.example.mymusic.utils.Music;

//不知道效果，没有测试
public class IncomingCallReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
            String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
            if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                // 电话响铃，暂停音乐播放
                Music.pause();
            } else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                // 电话挂断，恢复音乐播放（可选）
                Music.start();
            }
        }
    }
}
